<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace Qcloud\Cos;

class BucketStyleListener implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
    private $appId;
    public function __construct($appId)
    {
        $this->appId = $appId;
    }
    public static function getSubscribedEvents()
    {
        return ["command.after_prepare" => ["onCommandAfterPrepare", -230]];
    }
    public function onCommandAfterPrepare(\Guzzle\Common\Event $event)
    {
        $command = $event["command"];
        $bucket = $command["Bucket"];
        $request = $command->getRequest();
        if($command->getName() == "ListBuckets") {
            $request->setHost("service.cos.myqcloud.com");
        } else {
            if(($key = $command["Key"]) && is_array($key)) {
                $command["Key"] = $key = implode("/", $key);
            }
            $request->setHeader("Date", gmdate("D, d M Y H:i:s T"));
            $request->setPath(preg_replace("#^/" . $bucket . "#", "", $request->getPath()));
            if($this->appId != NULL && !endWith($bucket, "-" . $this->appId)) {
                $bucket = $bucket . "-" . $this->appId;
            }
            $request->getParams()->set("bucket", $bucket)->set("key", $key);
            $request->setHost($bucket . "." . $request->getHost());
            if(!$bucket) {
                $request->getParams()->set("cos.resource", "/");
            } else {
                $request->getParams()->set("cos.resource", "/" . rawurlencode($bucket) . ($key ? "/" . Client::encodeKey($key) : "/"));
            }
        }
    }
}
function endWith($haystack, $needle)
{
    $length = strlen($needle);
    if($length == 0) {
        return true;
    }
    return substr($haystack, -1 * $length) === $needle;
}

?>